
package com.vodafone.nowplus.android.peoplemail.mail.transport;

import java.io.OutputStream;
import java.net.Socket;

import android.util.Log;

import com.vodafone.nowplus.android.peoplemail.Account;
import com.vodafone.nowplus.android.peoplemail.K9;
import com.vodafone.nowplus.android.peoplemail.mail.Message;
import com.vodafone.nowplus.android.peoplemail.mail.MessagingException;
import com.vodafone.nowplus.android.peoplemail.mail.Transport;
import com.vodafone.nowplus.android.peoplemail.mail.filter.PeekableInputStream;
import com.vodafone.nowplus.android.peoplemail.mail.store.WebDavStore;

public class WebDavTransport extends Transport
{
    public static final int CONNECTION_SECURITY_NONE = 0;
    public static final int CONNECTION_SECURITY_TLS_OPTIONAL = 1;
    public static final int CONNECTION_SECURITY_TLS_REQUIRED = 2;
    public static final int CONNECTION_SECURITY_SSL_REQUIRED = 3;
    public static final int CONNECTION_SECURITY_SSL_OPTIONAL = 4;

    String host;
    int mPort;

    boolean mSecure;
    Socket mSocket;
    PeekableInputStream mIn;
    OutputStream mOut;
    private WebDavStore store;

    /**
     * webdav://user:password@server:port CONNECTION_SECURITY_NONE
     * webdav+tls://user:password@server:port CONNECTION_SECURITY_TLS_OPTIONAL
     * webdav+tls+://user:password@server:port CONNECTION_SECURITY_TLS_REQUIRED
     * webdav+ssl+://user:password@server:port CONNECTION_SECURITY_SSL_REQUIRED
     * webdav+ssl://user:password@server:port CONNECTION_SECURITY_SSL_OPTIONAL
     *
     * @param _uri
     */
    public WebDavTransport(Account account) throws MessagingException
    {
        store = new WebDavStore(account);
        if (K9.DEBUG)
            Log.d(this.getClass().getName(), ">>> New WebDavTransport creation complete");
    }

    @Override
    public void open() throws MessagingException
    {
        if (K9.DEBUG)
            Log.d(this.getClass().getName(), ">>> open called on WebDavTransport ");

        store.getHttpClient();
    }

    @Override
    public void close()
    {
    }

    @Override
    public void sendMessage(Message message) throws MessagingException
    {

        store.sendMessages(new Message[] { message });


    }

}
